package com.panopset.flywheel;

import java.io.StringWriter;

/**
 * <h5>p - Push</h5>
 *
 * <pre>
 *
 * ${&#064p name}Joe${&#064q}
 * </pre>
 *
 * Everything following this command is pushed into a String buffer, until a q
 * command is reached.
 *
 * @author Karl Dinwiddie
 *
 */
public class CommandPush extends MatchableCommand implements
        UserMatchableCommand {

    /**
     * Short HTML text for publishing command format in an HTML document.
     *
     * @return <b>${&#064;p name}</b>.
     */
    public static String getShortHTMLText() {
        return "${&#064;p name}";
    }

    /**
     * Command Push constructor.
     *
     * @param source
     *            Command source.
     * @param innerPiece
     *            Inner piece of the command.
     * @param template
     *            Template this command was declared in.
     */
    public CommandPush(final String source, final String innerPiece,
            final Template template) {
        super(source, innerPiece, template);
    }

    @Override
    public final void resolve(final StringWriter notUsed) {
        StringWriter sw = new StringWriter();
        resolveMatchedCommands(sw);
        getTemplate().getFlywheel().put(getParams(), sw.toString());
    }
}
